<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <script type="text/javascript" src="/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/lib/respond.min.js"></script>
    <script type="text/javascript" src="/js/vue/vue.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="/h-ui.admin/css/style.css"/>
    <script type="text/javascript" src="/lib/respond.min.js"></script>
    <!--<script>DD_belatedPNG.fix('*');</script>-->
    <title>客户列表</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 客户管理 <span
        class="c-gray en">&gt;</span> 客户列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                              href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c"> <!--日期范围：
        <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" id="datemin"
               class="input-text Wdate" style="width:120px;">
        <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax"
               class="input-text Wdate" style="width:120px;">-->
        <!--<input type="text" class="input-text" style="width:250px" placeholder="输入手机号" id="poNumber" name="">-->
        <input type="text" class="input-text" style="width:250px" placeholder="输入公司编号或公司名或手机号" id="poSupName" name="">
        <button type="button" class="btn btn-success" id="findempl" name=""><i class="Hui-iconfont">&#xe665;</i>搜索
        </button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a href="javascript:;" id="deleteAll" class="btn btn-danger radius"><i
                    class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
        <a href="javascript:;" onclick="addEvent('添加客户','admin-add.html','800','500')"
           class="btn btn-primary radius">
        <i class="Hui-iconfont">&#xe600;</i> 添加客户</a>
        <a href="#" onclick="excel()"
           class="btn btn-success radius">
        <i class="Hui-iconfont">&#xe644;</i> Excel导出</a>
    </span>

        <span class="r">共有数据：<strong id="strong"></strong> 条</span></div>

    <table class="table table-border table-bordered table-bg" id="app">
        <thead>
        <tr>
            <th scope="col" colspan="9">客户列表</th>
        </tr>
        <tr class="text-c">
            <th width="25">
                <label>
                    <input type="checkbox" id="checkAll">
                </label>
            </th>
            <th width="40">ID</th>
            <th width="130">操作</th>
            <th width="150">客户编号</th>
            <th width="150">客户名称</th>
            <th width="90">应收客户欠款</th>
            <th width="90">联系方式</th>
            <th width="130">联系人</th>
            <th width="150">客户状态</th>
            <th width="100">关联人员</th>
            <th width="100">地址</th>
            <th width="70">邮箱</th>
            <th width="150">联系人qq</th>
            <th width="150">备注</th>
        </tr>
        </thead>
        <tbody>
        <tr class="text-c" v-for="(item,index) in result">
            <td><input type="checkbox" id="box" :value="item.id"></td>
            <td>{{index+1}}</td>
            <td class="td-manage">
                <a style="text-decoration:none" class="ml-5"
                   @click="editEvent(item.id)('编辑','article-add.html','10001')" href="javascript:;" title="编辑">
                    <i class="Hui-iconfont">&#xe6df;</i>
                </a>
                <a title="删除" href="javascript:;" @click="delEvent(item.id)" class="ml-5"
                   style="text-decoration:none">
                    <i class="Hui-iconfont">&#xe6e2;</i>
                </a>

            </td>
            <td>{{item.cusNumber}}</td>
            <td>{{item.cusCompname}}</td>
            <td>{{item.cusMoney}}</td>
            <td>{{item.cusTele}}</td>
            <td>{{item.cusName}}</td>
            <td>{{item.cusFlag==1?"正常":"禁用"}}</td>
            <td>{{item.cusConnname}}</td>
            <td>{{item.cusAddress}}</td>
            <td>{{item.cusEmail}}</td>
            <td>{{item.cusQq}}</td>
            <td>{{item.cusRemarks}}</td>

        </tr>
        </tbody>
    </table>
</div>
<div id="pagenav" style="text-align: center"></div>

<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            result: []
        }
    });

    var getPurchasePageList = function (curr) {
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: '/customermanagement/customer/selectPage',
            data: {
                /*当前页*/
                current: curr || 1,
                /*每页大小*/
                size: 5,
                cusCompname: $("#poSupName").val(),
                cusTele: $("#poSupName").val(),
                cusNumber: $("#poSupName").val()
            },
            success: function (msg) {
                $("#strong").html(msg.total);
                app.result = msg.records;
                laypage({
                    cont: 'pagenav',//容器  值支持id名、原生dom对象，jquery对象,
                    pages: msg.pages,//总页数
                    first: '首页',
                    last: '尾页',
                    curr: curr || 1,//初始化页数
                    jump: function (obj, first) {
                        //触发分页后的回调
                        if (!first) {     //点击跳页触发函数自身，并传递当前页：obj.curr
                            getPurchasePageList(obj.curr);
                        }
                    }
                });
            }
        });
    };
    getPurchasePageList();
    $("#findempl").on('click', function () {
        getPurchasePageList();
    });


    /*删除客户*/
    var delEvent = function (id) {
        layer.confirm('你确定要删除吗？', {
            btn: ['是', '否']
        }, function () {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/customermanagement/customer/deleteCustomer',
                data: {
                    id: id
                },
                success: function (msg) {
                    if (msg==0) {
                        layer.msg('成功删除', {icon: 1});
                        getPurchasePageList();
                    }
                    if (msg==1){
                        layer.msg('该客户与我们还有金钱交易，不能删除！',{time:2000,icon:2});
                        getPurchasePageList();
                    }
                }
            })
        });
    };

    /*批量删除*/
    $("#deleteAll").click(function () {
        var arr = new Array();
        $("input:checkbox[id='box']:checked").each(function (i) {
            arr[i] = $(this).val();
        });
        if (arr[0] == null) {
            layer.msg("请选择要删除的客户！", {time: 2000, icon: 2})
        } else {
            layer.confirm('你确定要删除它们吗？', {
                btn: ['是', '否']
            }, function () {
                for (var i = 0; i < arr.length; i++) {
                    $.ajax({
                        type: 'POST',
                        dataType: 'json',
                        url: '/customermanagement/customer/deleteCustomer',
                        data: {
                            id: arr[i],
                        },
                        success: function (msg) {
                            if (msg==0) {
                                layer.msg('成功删除', {icon: 1});
                                getPurchasePageList();
                            }
                            if (msg==1){
                                layer.msg('该客户与我们还有金钱交易，不能删除！',{time:2000,icon:2});
                                getPurchasePageList();
                            }
                        }
                    });
                }
            }, function () {
                layer.msg('删除失败！', {time: 2000, icon: 2});
            });
            $("input:checkbox[id='box']:checked").attr("checked", false);
        }
        ;
    });

    /*编辑修改*/
    var editEvent = function (id) {

        layer.open({
            type: 2,
            title: '编辑用户',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['800px','600px'],
            content: '/customermanagement/customer/editCustomer?id=' + id,

            end: function () {
                getPurchasePageList();
                layer.msg('修改成功', {icon: 1});
            }

        });
    };

    /*增加客户*/
    var addEvent = function (customer) {

        layer.open({
            type: 2,
            title: '新增用户',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['800px','600px'],
            content: '/customermanagement/customer/addCustomer?',
            end: function () {
                getPurchasePageList();
                layer.msg('增加成功', {icon: 1});
            }

        });
    };


    function excel() {
        window.location.href = "/customermanagement/customer/getExcel"

    }

</script>
</body>
</html>